#include "menuwin.h"
#include "ui_menuwin.h"
#include <QMenu>
#include <QActionGroup>
#include <QTextCodec>
#include <QDebug>


MenuWin::MenuWin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MenuWin)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);//隐藏标题设置为顶层显示
    menu = new QMenu();
    menu->setGeometry(20,20,200,500);

    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);

    BGAction = new QActionGroup(this);

    actionSampleanalyse = new QAction(menu);
    actionSampleanalyse->setText(tr("样本分析"));

    QMenu *MenuReview = new QMenu();
    MenuReview->setTitle(tr("回顾"));
    actionListreview = new QAction(MenuReview);
    actionListreview->setText(tr("列表回顾                        "));
    MenuReview->addAction(actionListreview);

    actionGraphreview = new QAction(MenuReview);
    actionGraphreview->setText(tr("图形回顾                        "));
    MenuReview->addAction(actionGraphreview);


    QMenu *MenuQualitycontrol = new QMenu();
    MenuQualitycontrol->setTitle(tr("质控"));

    QMenu *MenuXJQualitycontrol = new QMenu();
    MenuXJQualitycontrol->setTitle(tr("L-J质控                        "));
    MenuQualitycontrol->addMenu(MenuXJQualitycontrol);
    actionXJQualitycontrolcount = new QAction(MenuQualitycontrol);
    actionXJQualitycontrolcount->setText(tr("计数                           "));
    MenuXJQualitycontrol->addAction(actionXJQualitycontrolcount);
    BGAction->addAction(actionXJQualitycontrolcount);
    actionXJQualitycontrolseting = new QAction(MenuQualitycontrol);
    actionXJQualitycontrolseting->setText(tr("设定                           "));
    MenuXJQualitycontrol->addAction(actionXJQualitycontrolseting);
    BGAction->addAction(actionXJQualitycontrolseting);

    QMenu *MenuXBQualitycontrol = new QMenu();
    MenuXBQualitycontrol->setTitle(tr("XB质控                         "));
    MenuQualitycontrol->addMenu(MenuXBQualitycontrol);
    actionXBQualitycontrolcount = new QAction(MenuQualitycontrol);
    actionXBQualitycontrolcount->setText(tr("设定                           "));
    MenuXBQualitycontrol->addAction(actionXBQualitycontrolcount);
    BGAction->addAction(actionXBQualitycontrolcount);
    actionXBQualitycontrolmap = new QAction(MenuQualitycontrol);
    actionXBQualitycontrolmap->setText(tr("图                            "));
    MenuXBQualitycontrol->addAction(actionXBQualitycontrolmap);
    BGAction->addAction(actionXBQualitycontrolmap);

    MenuQualitycontrol->addMenu(MenuXJQualitycontrol);
    MenuQualitycontrol->addMenu(MenuXBQualitycontrol);


    QMenu *MenuCalibration = new QMenu();
    MenuCalibration->setTitle(tr("校准"));
    manualactionCalibration  = new QAction(MenuCalibration);
    manualactionCalibration->setText(tr("人工校准                        "));
    MenuCalibration->addAction(manualactionCalibration);
    BGAction->addAction(manualactionCalibration);
    standardactionCalibration  = new QAction(MenuCalibration);
    standardactionCalibration->setText(tr("校准物校准                       "));
    MenuCalibration->addAction(standardactionCalibration);
    BGAction->addAction(standardactionCalibration);
    bloodactionCalibration  = new QAction(MenuCalibration);
    bloodactionCalibration->setText(tr("新鲜血校准                       "));
    MenuCalibration->addAction(bloodactionCalibration);
    BGAction->addAction(bloodactionCalibration);

    QMenu *MenuMactionFunction = new QMenu();
    MenuMactionFunction->setTitle(tr("性能"));
    actionsamplebase = new QAction(MenuMactionFunction);
    MenuMactionFunction->addAction(actionsamplebase);
    actionsamplebase->setText(tr("本底                           "));
    BGAction->addAction(actionsamplebase);
    actionreiteration = new QAction(MenuMactionFunction);
    MenuMactionFunction->addAction(actionreiteration);
    actionreiteration->setText(tr("重复性                          "));
    BGAction->addAction(actionreiteration);
    actionpollute = new QAction(MenuMactionFunction);
    MenuMactionFunction->addAction(actionpollute);
    actionpollute->setText(tr("携带污染物                        "));
    BGAction->addAction(actionpollute);
    actionageing = new QAction(MenuMactionFunction);
    MenuMactionFunction->addAction(actionageing);
    actionageing->setText(tr("老化                           "));
    BGAction->addAction(actionageing);

    QMenu *MenuSetting = new QMenu();
    MenuSetting->setTitle(tr("设置"));

    QMenu *MenusysSetting = new QMenu();
    MenusysSetting->setTitle(tr("系统设置                        "));
    MenuSetting->addMenu(MenusysSetting);
    actionassist = new QAction(MenusysSetting);
    MenusysSetting->addAction(actionassist);
    actionassist->setText(tr("辅助设置                       "));
    BGAction->addAction(actionassist);


    actionPrintSetting = new QAction(MenusysSetting);
    MenusysSetting->addAction(actionPrintSetting);
    actionPrintSetting->setText(tr("打印设置                         "));
    BGAction->addAction(actionPrintSetting);
    actioncommunicationSetting = new QAction(MenusysSetting);
    MenusysSetting->addAction(actioncommunicationSetting);
    actioncommunicationSetting->setText(tr("通信设置                       "));
    BGAction->addAction(actioncommunicationSetting);
    actionflag = new QAction(MenusysSetting);
    MenusysSetting->addAction(actionflag);
    actionflag->setText(tr("Flag报警灵敏度                   "));
    BGAction->addAction(actionflag);
    actiondictionary = new QAction(MenusysSetting);
    MenusysSetting->addAction(actiondictionary);
    actiondictionary->setText(tr("科室/送检者设置                    "));
    BGAction->addAction(actiondictionary);
    actionlaboratory = new QAction(MenusysSetting);
    MenusysSetting->addAction(actionlaboratory);
    actionlaboratory->setText(tr("实验室信息设置                  "));
    BGAction->addAction(actionlaboratory);
    actionDateSetting = new QAction(MenusysSetting);
    MenusysSetting->addAction(actionDateSetting);
    actionDateSetting->setText(tr("日期/时间设置                    "));
    BGAction->addAction(actionDateSetting);


    actionsuermanage = new QAction(MenuSetting);
    MenuSetting->addAction(actionsuermanage);
    actionsuermanage->setText(tr("用户管理                       "));
    BGAction->addAction(actionsuermanage);

    QMenu *MenuparaSetting = new QMenu();
    MenuparaSetting->setTitle(tr("参数设置                        "));
    MenuSetting->addMenu(MenuparaSetting);
    actionParamUnit = new QAction(MenuparaSetting);
    MenuparaSetting->addAction(actionParamUnit);
    actionParamUnit->setText(tr("参数单位设置                    "));
    BGAction->addAction(actionParamUnit);

    actionParamReferLimits = new QAction(MenuparaSetting);
    MenuparaSetting->addAction(actionParamReferLimits);
    actionParamReferLimits->setText(tr("参考范围设置                    "));
    BGAction->addAction(actionParamReferLimits);
    actionParamMicroscopy = new QAction(MenuparaSetting);
    MenuparaSetting->addAction(actionParamMicroscopy);
    actionParamMicroscopy->setText(tr("镜检参数设置                    "));
    BGAction->addAction(actionParamMicroscopy);
    actionParamResearch = new QAction(MenuparaSetting);
    MenuparaSetting->addAction(actionParamResearch);
    actionParamResearch->setText(tr("研究参数设置                    "));
    BGAction->addAction(actionParamResearch);
    actionmaintainsetting = new QAction(MenuSetting);
    MenuSetting->addAction(actionmaintainsetting);
    actionmaintainsetting->setText(tr("维护设置                       "));
    BGAction->addAction(actionmaintainsetting);
    actionreagentmanage = new QAction(MenuSetting);
    MenuSetting->addAction(actionreagentmanage);
    actionreagentmanage->setText(tr("试剂管理                       "));
    BGAction->addAction(actionreagentmanage);
    actiongainsetting = new QAction(MenuSetting);
    MenuSetting->addAction(actiongainsetting);
    actiongainsetting->setText(tr("增益设置                       "));
    BGAction->addAction(actiongainsetting);

    QMenu *MenuServe = new QMenu();
    MenuServe->setTitle(tr("服务"));
    actionmaintain = new QAction(MenuServe);
    MenuServe->addAction(actionmaintain);
    actionmaintain->setText(tr("维护                         "));
    BGAction->addAction(actionmaintain);
    actionselfcheck = new QAction(MenuServe);
    MenuServe->addAction(actionselfcheck);
    actionselfcheck->setText(tr("自检                         "));
    BGAction->addAction(actionselfcheck);
    actionneedle = new QAction(MenuServe);
    MenuServe->addAction(actionneedle);
    actionneedle->setText(tr("采样针调试                       "));
    BGAction->addAction(actionneedle);
    actiongain = new QAction(MenuServe);
    MenuServe->addAction(actiongain);
    actiongain->setText(tr("增益标定                        "));
    BGAction->addAction(actiongain);
    actionphotics = new QAction(MenuServe);
    MenuServe->addAction(actionphotics);
    actionphotics->setText(tr("光学调试                        "));
    BGAction->addAction(actionphotics);
    actiontemperaturepressuredemarcate = new QAction(MenuServe);
    MenuServe->addAction(actiontemperaturepressuredemarcate);
    actiontemperaturepressuredemarcate->setText(tr("温度压力标定                      "));
    BGAction->addAction(actiontemperaturepressuredemarcate);
    actionscreen = new QAction(MenuServe);
    MenuServe->addAction(actionscreen);
    actionscreen->setText(tr("触摸屏校准                      "));
    BGAction->addAction(actionscreen);
    actionworkbox = new QAction(MenuServe);
    MenuServe->addAction(actionworkbox);
    actionworkbox->setText(tr("高级工具箱                        "));
    BGAction->addAction(actionworkbox);
    actionlog = new QAction(MenuServe);
    MenuServe->addAction(actionlog);
    actionlog->setText(tr("日志                           "));
    BGAction->addAction(actionlog);
    actiontimesdebug = new QAction(MenuServe);
    MenuServe->addAction(actiontimesdebug);
    actiontimesdebug->setText(tr("时序调试                         "));
    BGAction->addAction(actiontimesdebug);


    QMenu *MenuStatus = new QMenu();
    MenuStatus->setTitle(tr("状态"));
    actionglobalcounter = new QAction(MenuStatus);
    MenuStatus->addAction(actionglobalcounter);
    actionglobalcounter->setText(tr("计数器                          "));
    BGAction->addAction(actionglobalcounter);
    actiontemperaturepressure = new QAction(MenuStatus);
    MenuStatus->addAction(actiontemperaturepressure);
    actiontemperaturepressure->setText(tr("温度与压力                        "));
    BGAction->addAction(actiontemperaturepressure);
    actionvoltagecurrent = new QAction(MenuStatus);
    MenuStatus->addAction(actionvoltagecurrent);
    actionvoltagecurrent->setText(tr("电压与电流                        "));
    BGAction->addAction(actionvoltagecurrent);
    actionsensor = new QAction(MenuStatus);
    MenuStatus->addAction(actionsensor);
    actionsensor->setText(tr("传感器                        "));
    BGAction->addAction(actionsensor);
    actionversions = new QAction(MenuStatus);
    MenuStatus->addAction(actionversions);
    actionversions->setText(tr("版本信息                        "));
    BGAction->addAction(actionversions);
    actionabout = new QAction(MenuStatus);
    MenuStatus->addAction(actionabout);
    actionabout->setText(tr("关于                         "));
    BGAction->addAction(actionabout);

    actionLogout = new QAction(menu);
    actionShutdown = new QAction(menu);

    menu->addAction(actionSampleanalyse);
    menu->addMenu(MenuReview);
    menu->addMenu(MenuQualitycontrol);
    menu->addMenu(MenuCalibration);
    menu->addMenu(MenuMactionFunction);
    menu->addMenu(MenuSetting);
    menu->addMenu(MenuServe);
    menu->addMenu(MenuStatus);
    menu->addAction(actionLogout);
    menu->addAction(actionShutdown);

    BGAction->addAction(actionSampleanalyse);
    actionLogout->setText(tr("注销"));
    BGAction->addAction(actionLogout);
    actionShutdown->setText(tr("关机"));
    BGAction->addAction(actionShutdown);
    ui->Btn_menu->setMenu(menu);

    QString sheet1 =
          "QMenu {background-color: #EFF4F3;color: #21825F;"
          "border-color: #21825F;"
          "font-size: 14px ; "
          "font-weight:bold; "
          "}"
          "QMenu::item{padding: 12px 110px 12px 12px;}"
          "QMenu::item:selected { background-color:#21825F;"
          "color: #EFF4F3;}"
          "QMenu::right-arrow{ image-position: center;"
          "image: url(:/image/images/menu_arrows_uncheck.png);}"
          "QMenu::right-arrow:selected { image-position: center;"
          "image: url(:/image/images/menu_arrows_check.png);}";

    QString sheet =
          "QMenu {background-color: #EFF4F3;color: #21825F;border-color: #21825F;"
          "font-size: 14px ; "
          "font-weight:bold; "
          "}"
          "QMenu::item{padding: 12px;}"
          "QMenu::item:selected { background-color:#21825F;"
          "color: #EFF4F3;}"
          "QMenu::right-arrow{ image-position: center;"
          "image: url(:/image/images/menu_arrows_uncheck.png);}"
          "QMenu::right-arrow:selected { image-position: center;"
          "image: url(:/image/images/menu_arrows_check.png);}";

    menu->setStyleSheet(sheet1);
    MenuReview->setStyleSheet(sheet);
    MenuMactionFunction->setStyleSheet(sheet);
    MenuQualitycontrol->setStyleSheet(sheet);
    MenuCalibration->setStyleSheet(sheet);
    MenuServe->setStyleSheet(sheet);
    MenuStatus->setStyleSheet(sheet);
    MenuSetting->setStyleSheet(sheet);
    MenusysSetting->setStyleSheet(sheet);
    MenuparaSetting->setStyleSheet(sheet);
    MenuXJQualitycontrol->setStyleSheet(sheet);
    MenuXBQualitycontrol->setStyleSheet(sheet);

   // 连接menu的信号
   connect(menu, SIGNAL(triggered(QAction*)), this , SLOT(showMenuPage(QAction*)));

}

MenuWin::~MenuWin()
{
    delete ui;
}

void MenuWin::showMenuPage(QAction *a)
{
      if(a == actionassist)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_AssistView);
      }
      else if(a == actionPrintSetting)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_PrintSetView);
      }
      else if(a == actionflag)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_FlagAlarmView);
      }
      else if(a == actioncommunicationSetting)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_CommuicationView);
      }
      else if(a == actionlaboratory)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_LabInfoSetView);
      }
      else if(a == actionDateSetting)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_DateTimeSetView);
      }
      else if(a == actionsuermanage)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_UserManagerView);
      }
      else if(a == actionmaintainsetting)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_MaintainView);
      }
      else if(a == actionreagentmanage)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ReagManageView);
      }
      else if(a == actiondictionary)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_DepartClinicanView);
      }
      else if(a == actiongainsetting)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_GainSettingView);
      }
      else if(a == actionParamResearch)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ParamReserachView);
      }
      else if(a == actionParamUnit)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ParamUnitView);
      }
      else if(a == actionParamMicroscopy)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ParamMicroscopeView);
      }
      else if(a == actionSampleanalyse)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_SampleAnalysisView);
      }
      else if(a == actionParamReferLimits)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ParamReferLimitsView);
      }
      else if(a == manualactionCalibration)
      {
          MainController::getInstance()->setCurrentWidgetID(MainController::E_ManualCalibrate);
      }

}
